package com.bit.inmap;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class MySQLHandler {
	//private Context ctx;
	private MySQLHelper helper;
	private SQLiteDatabase db;
	
	public MySQLHandler(Context ctx) {
		//this.ctx = ctx;
		helper = new MySQLHelper(ctx, "register.db", null, 1);

	}
		
	public static MySQLHandler open(Context ctx) throws SQLException{
		MySQLHandler handler = new MySQLHandler(ctx);
		return handler;
	}

	// close
	public void close() {
		db.close();
	}
	
	// SQL문 작성
	// INSERT
	public void insert(String name, String id, String pwd, String phone, String email, String birth) {
		db = helper.getWritableDatabase();

		ContentValues values = new ContentValues();
		values.put("name", name);
		values.put("id", id);
		values.put("pwd", pwd);
		values.put("phone", phone);
		values.put("email", email);
		values.put("birth", birth);

		db.insert("member", null, values);
		db.close();
	}
	
	// SELECT
	public Cursor selectAll() {
		db = helper.getReadableDatabase();

		Cursor c = db.query(true, "member", new String[] { "name", "id",
				"pwd", "phone", "email", "birth" }, null, null, null, null, null, null);
		if (c != null) {
		     c.moveToFirst();
		}
		db.close();
		return c;
	}
		
}
